#include <iostream>
#include <cstring>
using namespace std;

const int N = 1010;

int n, m;       //存储货物数量和容量
int v[N], w[N]; //货物信息
int f[N][N];    //状态表示方程

int main()
{
    freopen("cin.txt", "r", stdin);
    memset(f, 0, sizeof f);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> v[i] >> w[i];
    for (int i = 1; i <= n; ++i)     //从只能拿一个，递推到全部可以拿
        for (int j = 1; j <= m; ++j) //从容积为1，递推到容积最大
        {
            f[i][j] = f[i - 1][j];
            for (int k = 1; k * v[i] <= j; ++k) //k * v[i] > j后就失去意义了
                f[i][j] = max(f[i][j], f[i - 1][j - k * v[i]] + k * w[i]);
        }
    cout << f[n][m];
    return 0;
}